﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Manager_SysLogs : System.Web.UI.PageEx
{
    private string strPageCode = "S0000D";
    private string strLoginResult = string.Empty;
    private int iPageCount = 0;
    private int iRecordCount = 0;
    private string strQuery = " and AUId='0'";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            dpEnd.Text = DateTime.Now.ToShortDateString();
            dpStart.Text = DateTime.Now.AddDays(-1).ToShortDateString();
            DataBinds();
        }
    }
    private void DataBinds()
    {
        DataSet ds = WebBase.Comm.SelectByPage("dbActionLog", "*", strQuery, "aId", "aId", 0, 1, gridList.PageSize, gridList.PageIndex + 1, out iPageCount, out iRecordCount);
        gridList.RecordCount = iRecordCount;
        gridList.DataSource = ds;
        gridList.DataBind();
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string strStartDate = dpStart.Text;
        string strEndDate = dpEnd.Text;
        string strKeywordes = txtKeyword.Text.Trim();
        strQuery = " and 1=1";
        if (!string.IsNullOrEmpty(strStartDate))
            strQuery += " and aDateTime>='" + strStartDate + " 00:00:00'";
        if (!string.IsNullOrEmpty(strEndDate))
            strQuery += " and aDateTime<='" + strEndDate + " 23:59:59'";
        if(!string.IsNullOrEmpty(strKeywordes))
            strQuery += " and (aNote like '%" + strKeywordes + "%' or aIpAddress='" + strKeywordes + "' or aUid in (select mId from dbManager  where mUser='" + strKeywordes + "'))";
        DataBinds();
    }
    protected void gridList_PageIndexChange(object sender, FineUI.GridPageEventArgs e)
    {
        gridList.PageIndex = e.NewPageIndex;
        DataBinds();
    }
    protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
    {
        int iPageSize = 20;
        int.TryParse(ddlPageSize.SelectedValue, out iPageSize);
        gridList.PageSize = iPageSize;
        DataBinds();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DataBinds();
    }
}
